<template>
  <div id="homeBox">
    <div class="cardBox">
      <div class="cardItem" v-for="(item, index) in card" :key="index">
        <span :style="'color:' + item.color" :class="'iconfont ' + item.className"></span>
        <div class="cardItem-right">
          <p>{{ item.name }}</p>
          <p>{{ item.number }}</p>
        </div>
      </div>
    </div>
    <div style="margin: 20px 0" class="homeBox-content">
      <h3>数据统计</h3>
      <div ref="chartContainer" style="width: 100%; height: 400px"></div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import * as echarts from 'echarts'
const chartContainer = ref(null)
let chartInstance = null
const card = ref([
  {
    name: '总订单',
    number: 5486,
    className: 'icon-dingdan',
    color: 'green',
  },
  {
    name: '总销售额',
    number: 202466,
    className: 'icon-a-icon-xiaoshoue-fuben',
    color: 'blue',
  },
  {
    name: '今日订单数',
    number: 189,
    className: 'icon-dingdan1',
    color: 'red',
  },
  {
    name: '今日销售额',
    number: 2189,
    className: 'icon-dangrixiaoshoue',
    color: 'green',
  },
])
onMounted(() => {
  chartInstance = echarts.init(chartContainer.value)
  const option = {
    legend: {},
    tooltip: {},
    dataset: {
      source: [
        ['product', '订单', '销售额'],
        ['2023/05/17', 43.3, 85.8, 93.7, 10, 20, 30, 40],
        ['2023/05/18', 83.1, 73.4, 55.1, 10, 20, 30, 40],
        ['2023/05/19', 86.4, 65.2, 82.5, 10, 20, 30, 40],
        ['2023/05/20', 72.4, 53.9, 39.1, 10, 20, 30, 40],
        ['2023/05/21', 72.4, 53.9, 39.1, 10, 20, 30, 40],
        ['2023/05/22', 72.4, 53.9, 39.1, 10, 20, 30, 40],
        ['2023/05/23', 72.4, 53.9, 39.1, 10, 20, 30, 40],
      ],
    },
    xAxis: { type: 'category' },
    yAxis: {},
    series: [
      { type: 'bar', name: '订单' },
      { type: 'bar', name: '销售额' },
    ],
  }
  chartInstance.setOption(option)
})
</script>

<style scoped>
#homeBox {
  width: 100%;
  height: 100%;
  .cardBox {
    display: flex;
    justify-content: space-evenly;
    width: 100%;
    height: 100px;
    .cardItem {
      box-shadow: 2px 1px 10px 0px rgb(218, 218, 218);

      display: flex;
      justify-content: space-evenly;
      align-items: center;
      width: 24%;
      height: 100%;
      .iconfont {
        font-size: 50px;
      }
      .cardItem-right {
        display: flex;
        flex-direction: column;
        justify-content: center;
      }
    }
  }
}
</style>
